package team.star.werespos.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.star.werespos.model.vo.ResultVO;
import team.star.werespos.model.entity.Permission;
import team.star.werespos.service.PermissionService;
import team.star.werespos.util.Result;

import java.util.List;

/**
 * PermissionController class<br/>
 *
 * @author CAI
 * @since 2019/04/09
 */
@RequestMapping("/admin/permission")
@RestController
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

//    @PostMapping("/new")
    public ResultVO<?> newUser() {
        return Result.success();
    }

    /**
     * 获取权限列表
     *
     * @return
     */
    @GetMapping("/list")
    public ResultVO<List<Permission>> Permission() {
        return Result.success(
                permissionService.listPermission()
        );
    }

    /**
     * 修改权限信息
     */
//    @PostMapping("/{pid}/update")
    public ResultVO<?> updateById(
            @PathVariable Integer pid,
            @RequestBody Permission permission) {
        permission.setPid(pid);
        permissionService.updateById(permission);
        return Result.success();
    }

    /**
     * 删除权限
     */
//    @GetMapping("/{pid}/delete")
    public ResultVO<?> deleteById(@PathVariable Integer pid) {
        permissionService.deleteById(
                new Permission().setPid(pid)
        );
        return Result.success();
    }
}

